package com.example.springboot.controller;

import com.example.springboot.controller.dto.Result;
import com.example.springboot.controller.request.StudentPageRequest;
import com.example.springboot.entity.Student;
import com.example.springboot.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    IStudentService studentService;

    @GetMapping("/list")
    public Result list(){
        List<Student> students = studentService.list();
        return Result.success(students);
    }
    @GetMapping("/page")
    public Result page(StudentPageRequest studentPageRequest){

        return Result.success(studentService.page(studentPageRequest));
    }
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){
        studentService.deleteById(id);
        return Result.success();
    }
    @PostMapping("/save")
    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Student student = studentService.getById(id);
        return Result.success(student);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }






}
